from Control.Serialization import serMobile
from brocast.Serialization import serBlackCategory
from big_screen.utils import tools as t
import traceback


# 黑广播转化
def blackrecord_turn(message):
    """
    移动端发来的数据转化为标准数据(黑广播)
    :param message:
    :return:
    """
    # try:
    mob = serMobile()
    category = serBlackCategory()
    info = message.get("data")
    info_list = list()
    for content in info:
            # print(content)
        con = dict()
        con["category"] = category.table.get(num=content["category"])
        con["time"] = t.get_time(content.get("time"))
        con["lnglat"] = t.getLocation(content.pop("location"))
        con["mobile"] = mob.table.get(mobile=content.pop("phoneid"))
        con["record"] = content.get("record") + ".ogg"
        address_info = t.getaddress(con.get("lnglat"))
        con["address"] = address_info["formatted_address"]
        con["adcode"] = address_info["adcode"]
        con["freq"] = content.get("freq")
        con["contact"] = content.get("contact")
        con["common"] = content.get("common")
        info_list.append(con)
    return info_list
    # except Exception:
        # traceback.print_exc()
